<?php
if (!defined("OK")) { header("HTTP/1.0 404 Not Found"); }
ob_start();
$o = $db->uzklausa("SELECT s.*, u.`user_id`, u.`username` FROM ".T_SESSIONS." s, ".T_USERS." u WHERE s.`dabar`>'".(time() - 300)."' AND s.`user_id`=u.`user_id` ORDER BY s.`user_id` DESC");

$n = 0; $s = 0;
$online_masyvas = array();
while ($row = $db->masyvas($o)) {
	$online_masyvas[] = array(
	'user_id' => $row['user_id'],
	'username' => $row['username'],
	'dabar' => $row['dabar'],
	'spaud' => $row['spaud'],
	'ip' => $row['ip'],
	'psl' => $row['psl'],
	'narsykle' => $row['narsykle']
	);
	if ($row['user_id'] == 0) {
		if($row['spaud'] > 1) {
			++$s;
		}
	} else $n++;
}
$db->free_result($o);
$online = "<script type=\"text/javascript\">
function blocking(nr)
{
	if (document.layers) {
		current = (document.layers[nr].display == 'none') ? 'block' : 'none';
		document.layers[nr].display = current;
	} else if (document.all) {
		current = (document.all[nr].style.display == 'none') ? 'block' : 'none';
		document.all[nr].style.display = current;
	} else if (document.getElementById) {
		vista = (document.getElementById(nr).style.display == 'none') ? 'block' : 'none';
		document.getElementById(nr).style.display = vista;
	}
}
</script>";
if($n > 0 || $s > 0) $online .= "<a href='#svetaineje' onclick=\"blocking('num30'); return false\">";//?id,40
if ($s != 0) $online .= $s . galune($s, " svečias", " svečiai", " svečių");
if($n > 0 && $s > 0) $online .= " ir ";
if ($n != 0) $online .= $n . galune($n, " narys", " nariai", " narių");
if($n > 0 || $s > 0) $online .= "</a>";
?>
		<div class="title"><div style="padding-top:2px">
			<!--<a href="#svetaineje" onclick="blocking('num30'); return false"><img src="templates/<?=$conf['template']?>/images/plus1.gif" alt="Iskleisti" style="border:0;" /></a>-->
			Šiuo metu svetainėje: <? echo $online; ?>
		</div></div>
		<div class="vidus" style="display:none" id="num30">
		<?php
		//print_rr($online_masyvas);
		/*
		if (isset($url['id'])) { $failas = $url['id']; } //kuriame faile yra
		else { $failas = 'home'; }

		if (isset($_SERVER['HTTP_REFERER'])) { $ref = $_SERVER['HTTP_REFERER'];	} //is kur atejo
		else { $ref = 'Direct Link'; }
		*/
		?>
		<?php if($n > 0 ) { ?>
		<div style="font-size: 15px; font-weight:bold;"><?php echo galune($n, " Narys", " Nariai", " Narių");?>:</div>
			<table width="100%" border="0" cellpadding="0" cellspacing="0" class="table">
			<tr bgcolor="#F8F8FB">
				<th class="th" nowrap="nowrap">Slapyvardis</th>
				<th class="th" nowrap="nowrap">Nekvėpuoja</th>
				<th class="th" nowrap="nowrap">Spaudelioja</th>
				<th class="th" nowrap="nowrap">Puslapyje</th>
				<?php if(ADMIN) { ?>
				<th class="th" nowrap="nowrap">IP</th>
				<th class="th" nowrap="nowrap">Naršyklė</th>
				<?php } ?>
			</tr>
		<?php
		for($i = 0; $i < $n; $i++) {
			echo "
			<tr class=\"tr\">
				<td class=\"td\">".$online_masyvas[$i]['username']."</td>
				<td class=\"td\">".kada($online_masyvas[$i]['dabar'])."</td>
				<td class=\"td\">".$online_masyvas[$i]['spaud']."</td>
				<td class=\"td\">?".$online_masyvas[$i]['psl']."</td>";
			if(ADMIN) {
				echo "
				<td class=\"td\">".$online_masyvas[$i]['ip']."</td>
				<td class=\"td\">".htmlspecialchars($online_masyvas[$i]['narsykle'], ENT_QUOTES, 'UTF-8')."</td>";
			}
			echo "</tr>";
		}
		?></table>
		<?php } ?>
		<?php if($s > 0 ) { ?>
		<div style="font-size: 15px; font-weight:bold;"><?php echo galune($s, " Svečias", " Svečiai", " Svečių");?>:</div>
		<table width="100%" border="0" cellpadding="0" cellspacing="0" class="table">
			<tr bgcolor="#F8F8FB">
				<th class="th" nowrap="nowrap">Nekvėpuoja</th>
				<th class="th" nowrap="nowrap">Spaudelioja</th>
				<th class="th" nowrap="nowrap">Puslapyje</th>
				<?php if(ADMIN) { ?>
				<th class="th" nowrap="nowrap">IP</th>
				<th class="th" nowrap="nowrap">Naršyklė</th>
				<?php } ?>
			</tr>
		<?
		$kiek = $n+$s;
		for($i = $n; $i < $kiek; $i++) {
			echo "
			<tr class=\"tr\">
				<td class=\"td\">".kada($online_masyvas[$i]['dabar'])."</td>
				<td class=\"td\">".$online_masyvas[$i]['spaud']."</td>
				<td class=\"td\">?".$online_masyvas[$i]['psl']."</td>";
			if(ADMIN) {
				echo "
				<td class=\"td\">".$online_masyvas[$i]['ip']."</td>
				<td class=\"td\">".htmlspecialchars($online_masyvas[$i]['narsykle'], ENT_QUOTES, 'UTF-8')."</td>";
			}
			echo "</tr>";
		}
		?>
		</table>
		</div>
<?php
$result = ob_get_contents();
ob_end_clean();
?>
